{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "eb31b4ede96c4c5f8bc7f17856806a66",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Plot(antialias=3, axes=['x', 'y', 'z'], background_color=16777215, camera=[0.5141421356237309, 0.5141421356237…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\"\"\"\n",
    "Poisson equation with Dirichlet conditions.\n",
    "\n",
    "  -Laplace(u) = f    in the unit square\n",
    "            u = uD   on the boundary\n",
    "\n",
    "  uD = 1 + x^2 + 2*y^2\n",
    "  (f = -6)\n",
    "\"\"\"\n",
    "########################################################### fenics\n",
    "from fenics import *\n",
    "\n",
    "# Create mesh and define function space\n",
    "mesh = UnitSquareMesh(8, 8)\n",
    "V = FunctionSpace(mesh, \"P\", 1)\n",
    "\n",
    "# Define boundary condition\n",
    "uD = Expression(\"1 + x[0]*x[0] + 2*x[1]*x[1]\", degree=2)\n",
    "bc = DirichletBC(V, uD, \"on_boundary\")\n",
    "\n",
    "# Define variational problem\n",
    "w = TrialFunction(V)\n",
    "v = TestFunction(V)\n",
    "u = Function(V)\n",
    "f = Constant(-6.0)\n",
    "\n",
    "# Compute solution\n",
    "solve( dot(grad(w), grad(v))*dx == f*v*dx,  u, bc)\n",
    "\n",
    "########################################################### vtkplotter\n",
    "from vtkplotter.dolfin import plot\n",
    "\n",
    "plot(u, cmap='magma')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
